<?php

function unix_tail($lines, $file) 
{
    $random_filename = md5($file);
    
    shell_exec("tail -n $lines $file > /tmp/phptail_$random_filename"); 
    $output = file_get_contents("/tmp/phptail_$random_filename"); 
    unlink("/tmp/phptail_$random_filename"); 
    return $output; 
}

try {
    $sizeMultiple = isset($_REQUEST["size"]) ? $_REQUEST["size"] : 1;
    $linesToGet = $sizeMultiple * 10000;
    
    $output = unix_tail($linesToGet, '../log/update.log');
    
    $contentsLines = explode("\n", $output);
    
    $contentsLines = array_reverse($contentsLines);
    
    echo implode("<br />", $contentsLines);
}
catch (Exception $e) {
    echo "There was an exception: " . $e;
}